package com.gxa.saas.admin.service.impl;

import com.gxa.saas.admin.mapper.UserMapper;
import com.gxa.saas.admin.service.UserService;
import com.gxa.saas.core.entity.vo.OrderVO;
import com.gxa.saas.core.entity.vo.UsersVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author cowboy
 * @Date 2022/7/19 15:54
 * @Version 1.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public List<UsersVO> QueryUser() {

        List<UsersVO> user = this.userMapper.QueryUser();

        if (user.size() != 0) {
            for (int i = 0; i < user.size(); i++) {
                OrderVO order = this.userMapper.QueryOrder(user.get(i).getId());
                user.get(i).setOrder(order);

            }
            return user;
        }else {
            return null;
        }
    }

    @Override
    public List<UsersVO> QueryUserByCondition(String keyword, LocalDateTime time) {

        List<UsersVO> user = this.userMapper.QueryUserByCondition(keyword, time);

        if (user.size() != 0) {

            for (int i = 0; i < user.size(); i++) {
                OrderVO order = this.userMapper.QueryOrder(user.get(i).getId());
                user.get(i).setOrder(order);

            }
            return user;
        }else {
            return null;
        }



    }

    @Override
    public void UpdateUser(UsersVO userVO) {
        this.userMapper.UpdateUser(userVO.getId(), userVO.getStatus());
    }

    @Override
    public void DeleteUser(Integer id) {
        this.userMapper.DeleteUser(id);
    }
}
